package com.easthome.controller;


import com.easthome.constant.MessageConstant;
import com.easthome.pojo.SetMeal;
import com.easthome.result.Result;
import com.easthome.service.SetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 手机移动端端套餐管理
 */
@RestController
@RequestMapping("/setMeal")
public class SetMealController {
    @Autowired
    private SetMealService setMealService;

    /**
     * 移动端查询套餐请求 请求参数是套餐id
     */
    @GetMapping("/querySetMealById")
    public Result querySetMealById(Integer id) {
        SetMeal setMeal = setMealService.querySetMealById(id);
        if (setMeal == null) {
            //查询失败
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
        return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setMeal);
    }

    /**
     * 查询所有套餐
     * @return
     */
    @PostMapping("/querySetMealAll")
    public Result querySetMealAll() {
        List<SetMeal> setMeals = setMealService.querySetMealAll();
        if (setMeals == null) {
            //查询失败
            return new Result(false, MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
        return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS, setMeals);
    }
}
